package net.suncaper.demo.service;

import net.suncaper.demo.domain.*;
import net.suncaper.demo.mapper.*;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class GraduateServiceImpl implements GraduateService{


    @Autowired
    private MediumInspectionMapper mediumInspectionMapper;
    @Autowired
    private SelectQuestionMapper selectQuestionMapper;
    @Autowired
    private MediumReviewMapper mediumReviewMapper;
    @Autowired
    private GraduationMapper graduationMapper;
    @Autowired
    private GraduationReviewMapper graduationReviewMapper;
    @Override
    public void saveMediumInspection(MediumInspection mediumInspection) {
          mediumInspectionMapper.insert(mediumInspection);
    }

    @Override
    public List<MediumInspection> findMediumInspection() {
        return mediumInspectionMapper.selectByExampleWithBLOBs(new MediumInspectionExample());
    }

    @Override
    public MediumInspection findMediumInspectionById(BigDecimal id) {
        return mediumInspectionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateMediumInspection(MediumInspection mediumInspection) {
        mediumInspectionMapper.updateByPrimaryKeyWithBLOBs(mediumInspection);
    }

    @Override
    public List<MediumReview> FindMediumReview() {
        return mediumReviewMapper.selectByExampleWithBLOBs(new MediumReviewExample());
    }

    @Override
    public MediumReview findMediumReview(BigDecimal id) {
        return mediumReviewMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveMediumReview(MediumReview mediumReview) {
          mediumReviewMapper.insert(mediumReview);
    }

    @Override
    public void saveGraduation(Graduation graduation) {
        graduationMapper.insert(graduation);
    }

    @Override
    public List<Graduation> findGraduation() {
        return graduationMapper.selectByExampleWithBLOBs(new GraduationExample());
    }

    @Override
    public Graduation findGraduationById(BigDecimal id) {
        return graduationMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateGraduation(Graduation graduation) {
        graduationMapper.updateByPrimaryKeyWithBLOBs(graduation);
    }

    @Override
    public List<GraduationReview> FindGraduationReview() {
        return graduationReviewMapper.selectByExampleWithBLOBs(new GraduationReviewExample());
    }

    @Override
    public GraduationReview findGraduationReview(BigDecimal id) {
        return graduationReviewMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveGraduationReview(GraduationReview graduationReview) {
         graduationReviewMapper.insert(graduationReview);
    }
    @Override
    public BigDecimal findSelectQuestionByid(String UserId){
        List<SelectQuestion>selectQuestions=selectQuestionMapper.selectByExample(new SelectQuestionExample());
        BigDecimal a=new BigDecimal(0);
        for(int i=0;i<selectQuestions.size();i++) {
            if (selectQuestions.get(i).getStudentId().equals(UserId)){
                return selectQuestions.get(i).getSelectQuestionId();
            }
        }
        return a;
    }
    @Override
    public BigDecimal findMediumInspectionByStudentId(String UserId){
        List<MediumInspection> mediumInspections=mediumInspectionMapper.selectByExampleWithBLOBs(new MediumInspectionExample());
        for (int i=0;i<mediumInspections.size();i++){
            if(mediumInspections.get(i).getStudentId().equals(UserId)){
                return mediumInspections.get(i).getMediumInspectionId();
            }
        }
        BigDecimal a=new BigDecimal(0);
        return a;
    }
}
